package com.wpw.dream.common;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

public class LoginUser {

	private Long id;

	private String name;

	private Long loginTime;

	// 用户权限集合
	private List<Authority> authoritys;

	// 用户权限Url集合
	private Set<String> authorityUrls;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Long loginTime) {
		this.loginTime = loginTime;
	}

	public List<Authority> getAuthoritys() {
		return authoritys;
	}

	public void setAuthoritys(List<Authority> authoritys) {
		this.authoritys = authoritys;
		authorityUrls = new HashSet<String>();
		for (Authority authority : authoritys) {
			authorityUrls.add(authority.getAuthorityUrl());
		}
	}

	public Set<String> getAuthorityUrls() {
		return authorityUrls;
	}
	
	/**
	 * 
	 * @Description：
	 * @author: wupengwei
	 * @date: 2017年2月4日 下午4:16:55
	 * @param code 权限编码
	 * @return
	 */
	public Boolean hasAuthority(String code) {
		if (this.authoritys == null || StringUtils.isBlank(code)) {
			return false;
		}
		Boolean flag = false;
		for (Authority authority : authoritys) {
			if (code.equals(authority.getAuthorityId())) {
				flag = true;
				break;
			}
		}
		return flag;
	}
}
